class HouseItem:

    def __init__(self, name, area):
        self.name = name
        self.area = area

    def __str__(self):

        return "[%s] 占地 %.2f" % (self.name, self.area)


class House:

    def __init__(self, house_type, area):
        self.house_type = house_type
        self.area = area

        # 剩余面积
        self.free_area = area
        # 家具名称列表
        self.item_list = []

    
    def __str__(self):

        # Python 能够将一对括号中的代码自动连接在一起
        return ("户型：%s\n总面积：%.2f[剩余：%.2f]\n家具：%s" % 
            (self.house_type, self.area, self.free_area, self.item_list))


    def add_item(self, item):
        """添加家具的方法"""

        print("要添加 %s" % item.name)

        if self.free_area >= item.area:
            self.free_area -= item.area
            self.item_list.append(item.name)
        else:
            print("× 添加 %s 失败：房子剩余面积不足" % item.name)


# 创建家具
bed = HouseItem("席梦思", 20)
print(bed)

chest = HouseItem("衣柜", 3)
print(chest)

table = HouseItem("餐桌", 5)
print(table)

print("=" * 50)

# 创建房子对象
my_house = House("两室一厅", 60)
print(my_house)

print("-" * 50)

my_house.add_item(bed)
print(my_house)

print("-" * 50)

my_house.add_item(chest)
print(my_house)

print("-" * 50)

my_house.add_item(table)
print(my_house)

print("-" * 50)
big_item = HouseItem("超级大件家具", 35)
my_house.add_item(big_item)
print(my_house)